package com.alesj.newsfeed.bool.impl;

import java.util.Set;

import com.alesj.newsfeed.bool.Condition;
import com.alesj.newsfeed.bool.ConditionCreator;
import com.alesj.newsfeed.bool.Executor;

/**
 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
 */
public class PreToken<C> extends SimpleToken<C> {
    public PreToken(ConditionCreator<C> conditionCreator, String string) {
        super(conditionCreator, string.substring(1, string.length() - 1));
    }

    public Condition<C> value() {
        return new LazyCondition();
    }

    private class LazyCondition implements Condition<C> {
        public Set<C> execute() {
            Executor<C> executor = new ExecutorImpl<C>(new TokenizerImpl<C>(creator));
            return executor.execute(string);
        }
    }
}
